package com.weipai.springboot.module.dao.impl;

import com.weipai.springboot.model.Goods;
import com.weipai.springboot.model.GoodsPrice;
import com.weipai.springboot.model.Product;
import com.weipai.springboot.model.api.GoodsItem;
import com.weipai.springboot.module.dao.GoodsDao;
import com.weipai.springboot.module.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/24 10:12
 */
@Repository
public class GoodsDaoImpl implements GoodsDao {

    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private GoodsItemMappper goodsItemMappper;
    @Autowired
    private GoodsOptionMapper goodsOptionMapper;
    @Autowired
    private SpecialGoodsMapper specialGoodsMapper;

    //保存
    @Override
    public void save(Goods goods) {
        goodsMapper.insert(goods);
    }

    //删除商品
    @Override
    public int deleteByGoodsById(String id) {
        //逻辑删除关联数据
        goodsOptionMapper.updateDelStatusByGoodsId(id);
        return goodsMapper.deleteByGoodsById(id);
    }

    //更改商品的状态
    @Override
    public int changeGoodsStatus(String id, Integer status) {
        return goodsMapper.changeGoodsStatus(id, status);
    }

    //通过货品编号查出所有的商品
    @Override
    public List<Goods> selectGoodsBySpuNumber(String spuNumber) {
        return goodsMapper.selectGoodsBySpuNumber(spuNumber);
    }

    //商品的统一保存
    @Override
    public void save(List<Goods> goodsList) {
        int size01 = goodsList.size();
        for (int i = 0; i < size01; i++) {
            goodsMapper.insert(goodsList.get(i));
        }
    }

    @Override
    public List<Map<String, Object>> searchGoodsByCategoryId(String categoryId, Integer start, int size) {
        return goodsMapper.searchGoodsByCategoryId(categoryId, start, size);
    }

    @Override
    public Integer countGoodsByCategoryId(String categoryId) {
        return goodsMapper.countGoodsByCategoryId(categoryId);
    }

    @Override
    public List<Map<String, Object>> searchBoutiqueGoods(String shopId, String categoryId, Integer size) {
        return goodsMapper.searchBoutiqueGoods(shopId, categoryId, size);
    }

    @Override
    public List<Map<String, Object>> searchPopularBountiqueGoods(String shopId, Integer size) {
        return goodsMapper.searchPopularBountiqueGoods(shopId, size);
    }

    @Override
    public List<Map<String, Object>> searchPopularGoodsByShop(String shopId, Integer start, Integer size) {
        return goodsMapper.searchPopularGoodsByShop(shopId, start, size);
    }

    @Override
    public List<Map<String, Object>> searchBigBrandBountiqueGoods(Integer size) {
        return goodsMapper.searchBigBrandBountiqueGoods(size);
    }

    @Override
    public List<Map<String, Object>> searchRelatedGoods(String goodsId, Integer size) {
        String categoryId = goodsMapper.getProductCategoryId(goodsId);
        return goodsMapper.searchRelatedGoods(categoryId, size);
    }

    @Override
    public List<Map<String, Object>> searchRecommendGoods(String categoryId, Integer size) {
        return goodsMapper.searchRecommendGoods(categoryId, size);
    }

    @Override
    public List<Map<String, Object>> searchSpecialGoods(int page, int size) {
        return goodsMapper.searchSpecialGoods((page - 1) * size, size);
    }

    @Override
    public Integer countSpecialGoods() {
        return goodsMapper.countSpecialGoods();
    }

    @Override
    public List<Map<String, Object>> searchNewGoods(Integer size) {
        return goodsMapper.searchNewGoods(size);
    }

    @Override
    public Goods selectByPrimaryKey(String goodsId) {
        return goodsMapper.selectByPrimaryKey(goodsId);
    }

    //通过shopid  搜索 商品数量
    @Override
    public int countByShop(String shopId) {
        return goodsMapper.countByShop(shopId);
    }

    //通过商品编号查询商品的基础信息
    @Override
    public List<Map<String, Object>> getGoodsInfoBySkuNumber(String spuNumber) {
        return goodsMapper.getGoodsInfoBySkuNumber(spuNumber);
    }

    //查询此店铺下面一共有多少货品
    @Override
    public Integer getGoodsAmountByShopId(String shopId) {
        return goodsMapper.getGoodsAmountByShopId(shopId);
    }

    //查询产品图片、商品名称、商品规格
    @Override
    public Map<String, Object> getGoodsInfoByGoodsId(String goodsId) {
        return goodsMapper.getGoodsInfoByGoodsId(goodsId);
    }

    @Override
    public GoodsItem getGoodsItemById(String id) {
        return goodsItemMappper.getGoodsItemById(id);
    }

    @Override
    public List<GoodsItem> getGoodsItemByAll() {
        return goodsItemMappper.getGoodsItemByAll();
    }


    @Override
    public List<Map<String, Object>> getGoodsPropsById(String id) {
        return goodsItemMappper.getGoodsPropsById(id);
    }
    

    //修改商品
    @Override
    public int updateGoods(Goods goods) {
        return goodsMapper.updateByPrimaryKeySelective(goods);
    }

    //分页查询单一货品的所有商品
    @Override
    public List<Map<String, Object>> selectAllGoodsByProductId(Integer start, Integer size, String spuNumber) {
        return goodsMapper.selectAllGoodsByProductId(start, size, spuNumber);
    }

    //分页查询单一货品的所有商品
    @Override
    public Integer selectAllGoodsByProductIdAmount(String spuNumber) {
        return goodsMapper.selectAllGoodsByProductIdAmount(spuNumber);
    }

    //通过product的id查询商品的id
    @Override
    public List<Map<String, Object>> getGoodsIdByProductId(String spuNumber) {
        return goodsMapper.getGoodsIdByProductId(spuNumber);
    }

    @Override
    public List<Map<String, Object>> searchGoods(Integer start, Integer size, String search) {
        return goodsMapper.searchGoods(start, size, search);
    }

    @Override
    public Integer searchGoodsAmount(String search) {
        return goodsMapper.searchGoodsAmount(search);
    }

    //商品报表信息
    @Override
    public List<Map<String, Object>> goodsStatement(int start, Integer end) {
        return goodsMapper.goodsStatement(start, end);
    }

    //商品数量
    @Override
    public int getGoodsAmount() {
        return goodsMapper.getGoodsAmount();
    }

    //得到商品的skuNumber
    @Override
    public Map<String, Object> getSkuNumberByGoodsId(String goodsId) {
        return goodsMapper.getSkuNumberByGoodsId(goodsId);
    }

    //修改商品的销售数量
    @Override
    public int updateGoodsSoldOutNumber(String sku, Integer goodsNumber) {
        return goodsMapper.updateGoodsSoldOutNumber(sku, goodsNumber);
    }

    @Override
    public Map<String, Object> getMaxSkuNumberFlag(String spuNumber) {
        return goodsMapper.getMaxSkuNumberFlag(spuNumber);
    }

    @Override
    public Map<String, Object> getMaxSkuNumber() {
        return goodsMapper.getMaxSkuNumber();
    }

    //秒杀商品和会场产品--前端商品详情
    @Override
    public Map<String, Object> getSpecialGoodsInfo(String id) {
        return specialGoodsMapper.getSpecialGoodsInfo(id);
    }

    //通过商品的id查询出评论商品赠送的积分
    @Override
    public Map<String, Object> getCommentIntegralByGoodsId(String goodsId) {
        return goodsMapper.getCommentIntegralByGoodsId(goodsId);
    }

    //app前端获取商品价格
    @Override
    public List<Map<String, Object>> getGoodsInfoAndPriceBySpuNumber(String spuNumber, String memberLevelId) {
        return goodsMapper.getGoodsInfoAndPriceBySpuNumber(spuNumber, memberLevelId);
    }

    @Override
    public List<Map<String, Object>> getGoodsInfoAndPriceBySkuNumber(String skuNumber, String memberLevelId) {
        return goodsMapper.getGoodsInfoAndPriceBySkuNumber(skuNumber, memberLevelId);
    }


}
